﻿Imports System.Data.OleDb
Public Class Poll
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_poll_Click(sender As Object, e As EventArgs) Handles btn_poll.Click
        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TwilightConn").ConnectionString)
        conn.Open()
        Dim rmSql As String = "DELETE FROM TeamPollVotes WHERE Voter=@f1"
        Dim rmCmd As New OleDbCommand(rmSql, conn)
        rmCmd.CommandType = CommandType.Text
        rmCmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        rmCmd.ExecuteNonQuery()

        Dim sql As String = "INSERT INTO TeamPollVotes(Voter,Team) VALUES (@f1,@f2)"
        Dim addCmd As New OleDbCommand(sql, conn)
        addCmd.CommandType = CommandType.Text
        addCmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        addCmd.Parameters.AddWithValue("@f2", rbl_poll.SelectedValue)
        addCmd.ExecuteNonQuery()
        GridView1.DataBind()
        conn.Close()
        Response.Redirect("~/Poll.aspx")

    End Sub
End Class